<%@ page language="java" contentType="text/html; charset=utf-8"%>
<%
	if (!"".equals(session.getAttribute("session.user_id"))) {
		//response.sendRedirect("/cms/sales/salesList.jsp");
	} 
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
	<title>행복천사콜</title>
	<link rel="stylesheet" type="text/css" href="../css/base.css"/>
	<link rel="stylesheet" type="text/css" href="../css/default.css"/>
	<link rel="stylesheet" type="text/css" href="../css/cms.css"/>
	<link rel="stylesheet" type="text/css" href="../css/smoothness/jquery-ui-1.8.17.custom.css" media="screen" />
	<script type="text/javascript" src="../js/jquery-1.7.2.min.js"></script>
	<script type="text/javascript" src="../js/jquery-ui-1.8.18.custom.min.js" charset="utf-8"></script>
	<script type="text/javascript" src="../js/jquery.maskedinput-1.3.min.js" charset="utf-8"></script>
	<script type="text/javascript" src="../js/common.js" charset="utf-8"></script>
	<script type="text/javascript">
	$(document).ready(function() {

		$('#mid').focus();
  
		var mid = getCookie("mid");
		if (mid != "") {
			$("#mid").val(mid);
			$("#mid_save").attr("checked", true);
			$("#mid").css("background-image","none");
			$("#mid").css("background-color","#eeeeee");
			$("#mpass").focus();
		}

		$("#mid").keyup(function(e) {
			if ($(this).val() == "") {
				$(this).css("background","url(../admin/images/bg_mid.gif)");
			} else {
				$(this).css("background-image","none");
				$(this).css("background-color","#eeeeee");
			}
		}).blur(function(e) {
			if ($(this).val() == "") {
				$(this).css("background","url(../admin/images/bg_mid.gif)");
			} else {
				$(this).css("background-image","none");
				$(this).css("background-color","#eeeeee");
			}
		});

		$("#mpass").keydown(function(e) {
			if ($(this).val() == "") {
				$(this).css("background","url(../admin/images/bg_mpass.gif)");
			} else {
				$(this).css("background-image","none");
				$(this).css("background-color","#eeeeee");
			}
		}).focus(function() {
			$(this).css("background-image","none");
			$(this).css("background-color","#eeeeee");
		}).blur(function() {
			if ($(this).val() == "") {
				$(this).css("background","url(../admin/images/bg_mpass.gif)");
			} else {
				$(this).css("background-image","none");
				$(this).css("background-color","#eeeeee");
			}
		});


		//로그인버튼
		$('#login_btn').click(function(){//JSON호출 버튼이벤트

			if ($("#mid").val() == "") {
				alert("아이디를 입력하세요");
				$("#mid").focus();
				return false;
			}

			//if ($("#mpass").val() == "") {
			//	alert("비밀번호를 입력하세요");
		//		$("#mpass").focus();
			//	return false;
			//}

			$.ajax({
				url: '../admin/login.do',
				type: "POST",
			    dataType: 'json',//html,text,json
			    data: { //파라미터
			    	user_id : $('#mid').val(),
					user_pw : $('#mpass').val()
			    },
			    error: function(data, status, err){
			    	alert(err);
			    },
				success: function(data){
					if (data.result) {
						if (document.getElementById("mid_save").checked) {
				    		saveCookie("mid", $("#mid").val(), 30);
				    	} else {
				    		saveCookie("mid", $("#mid").val(), -1);
				    	}

						if ($("#returnUrl").val()=="") {
							document.location.href = data.nextUrl;
						} else {
							document.location.href = $("#returnUrl").val();
						}
					} else {
						$('#mpass').val("");
						$('#mpass').focus();
						alert(data.message);
					}
			    }
			});

		});

		//비밀번호에서 엔터입력시 로그인 실행.
		$('#mpass').keyup(function(e) {
			if (e.keyCode == 13) {
				$('#login_btn').click();
			}
		});

	});
	</script>
</head>
<body>
<div id="wrap">
	<div id="login">
		<div id="login_page">
		 	<div id="login_box">
				<img src="../admin/images/text_01.jpg"  />
				<div id="input_lay">
					<form name="loginForm" id="loginForm">
						<input type="hidden" name="returnUrl" id="returnUrl" value="<%=(request.getParameter("referUrl")==null)?"":request.getParameter("referUrl")%>"/>
						<input type="text" name="mid" id="mid" class="login_input" value=""/>
						<input type="password" name="mpass" id="mpass" class="login_input" value="" />
					</form>
				</div>

				<div id="login_bt">
					<a href="#none" id="login_btn"><img src="../admin/images/login_button.jpg"/></a>
					<input type="checkbox" name="mid_save" id="mid_save" />아이디저장
				</div>
			</div>
		</div>
	</div>
</div>
</body>
</html>
